package Exercises;/*
 *
 * @author 陈粒
 * @version 创建时间：2021/7/2 17:04
 */
/**
 * 练习题:多次生成随机数,并打印第一次出现大于0.999 时的次数与这时生成的随机数
 * Math.random()生成[0,1)区间的double类型的数
 */

import java.util.*;

public class Random_Number {
    public static void main(String[] args) {
        double[] ran_num = new double[10];
        boolean flag = true;
        boolean flag2 = true;
        for (int i = 0; i < ran_num.length; i++) {
            ran_num[i] = Math.random() + 0.5;
            if (ran_num[i] > 0.999 && flag2 == true) {
                System.out.println("第一次出现大于0.999的次数为:" + (i + 1) + " " + "这时生成的随机数如下：");
                for (int j = 0; j <= i; j++) {
                    System.out.print(ran_num[j] + " ");
                }
                System.out.println();
                flag = false;
                flag2 = false;
                continue;
            }
        }
        if (flag == true) {
            System.out.println("没有大于0.999的数:" + "全部随机数为：" + Arrays.toString(ran_num));
        } else {
            System.out.println("有大于0.999的数:" + "全部随机数为：" + Arrays.toString(ran_num));
        }
    }
}
